@extends('users.app')
@section('title', '用户列表')
@section('content')
<div class="row">
    <div class="col-12 col-xl-10 m-b-10">
    <div class="card">
        <div class="card-header border-bottom">
            <h4 class="card-title">用户列表</h4>
        </div>
        <div class="card-body">
            <div class="row col-sm-10">
              <form action="{{ route('members.index') }}" method="GET">
              <div class="form-group">
                <div class="input-group">
                  <input class="form-control" type="text" name="name" value="{{ old('name', Request::input('name') ?: '')}}" placeholder="输入用户名/用户ID">
                  <div class="input-group-append">
                    <button class="btn btn-info" type="submit">搜索</button>
                  </div>
                </div>
              </div>
            </form>
            </div>
            <div class="table-responsive">
                <table class="table table-bordered mb-0">
                    <thead>
                        <tr>
                            @if ($user->hasRole('Founder'))
                            <th>ID</th>
                            @endif
                            <th>用户名</th>
                            <th>QQ</th>
                            @can('destroy', $user)
                            <th>扣量阈值</th>
                            <th>比例</th>
                            <th>单价</th>
                            @endcan
                            <th>类别</th>
                            <th>注册时间</th>
                            <th>查看数据</th>
                            @can('destroy', $user)<th>操作</th>@endcan
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($members as $member)
                        <tr>
                            @if ($user->hasRole('Founder'))
                            <th scope="row">{{ $member->id }}</th>
                            @endif
                            <td>{{ $member->name }}</td>
                            <td>{{ $member->qq ?: '未填写' }}</td>
                            @can('destroy', $member)
                            <td>{{ ($member->kouliang_min === -1) ? '系统默认' : $member->kouliang_min }}</td>
                            <td>{{ ($member->kouliang === '0.00') ? '系统默认' : $member->kouliang }}</td>
                            <td>{{ ($member->price === '0.00') ? '系统默认' : $member->price }}</td>
                            @endcan
                            <td>@if($member->hasRole('Founder')) <span style="color:red;">管理员</span>@else{{ $member->hasRole('Daili') ? '代理' : '普通会员' }}@endif</td>
                            <td>{{ $member->created_at->diffForHumans() }}</td>
                            <td>
                              <a href="{{ route('view_counts.index', ['user_id' => $member->id] )}}">查看数据</a>
                            </td>

                            @can('destroy', $user)<td>
                              @if($user->hasRole('Founder'))
                                <a href="{{ route('members.edit', $member->id)}}" class="btn btn-sm btn-info">编辑</a>
                                @if ($member->role > 0)
                                <form action="{{ route('members.ban', $member->id) }}" method="POST" style="display: inline;" onsubmit="return confirm('封禁后用户无法登录? 确认封禁?');">
                                  {{csrf_field()}}
                                  <input type="hidden" name="role" value="0">
                                  <button type="submit" class="btn btn-sm btn-warning">封禁</button>
                                </form>
                                @else
                                <form action="{{ route('members.ban', $member->id) }}" method="POST" style="display: inline;">
                                  {{csrf_field()}}
                                  <input type="hidden" name="role" value="1">
                                  <button type="submit" class="btn btn-sm btn-primary">解封</button>
                                </form>
                                @endif
                                <form action="{{ route('members.destroy', $member->id) }}" method="POST" style="display: inline;" onsubmit="return confirm('Delete? Are you sure?');">
                                  {{csrf_field()}}
                                  <input type="hidden" name="_method" value="DELETE">

                                  <button type="submit" class="btn btn-sm btn-danger">删除</button>
                                </form>
                              @endif
                            </td>@endcan
                        </tr>
                        @endforeach
                    </tbody>
                </table>
                <div class="mt-2">
                  {!! $members->appends(Request::except('page'))->render() !!}
                </div>
            </div>
        </div>
      </div>
    </div>
</div>
@stop
